package com.leha.apidemo.service.impl;

import com.leha.apidemo.dao.AccountMapper;
import com.leha.apidemo.entity.Account;
import com.leha.apidemo.entity.AccountExample;
import com.leha.apidemo.service.AccountService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by fangzhipeng on 2017/4/20.
 */
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountMapper accountMapper2;

    @Override
    @Transactional
    public void transfer() throws RuntimeException{
        Account ac = new Account();
        ac.setId(1);ac.setMoney((double) 90);ac.setName("aa");
        accountMapper2.updateByPrimaryKey(ac);
        ac.setId(null);
        accountMapper2.insertSelective(ac);
        if(true) {
            throw new RuntimeException("sd");
        }
        ac.setId(2);ac.setMoney((double) 110);
        accountMapper2.updateByPrimaryKey(ac);
    }

    @Override
    public List<Account> getList() {
        PageHelper.startPage(1, 2);
        return accountMapper2.selectByExample(new AccountExample());
    }
}
